#include <iostream>
#include <queue>
using namespace std;

struct tagStudent {
    string id;
    string name;
    int score;
public:
    tagStudent(string id, string name, int score) {
        this->id = id;
        this->name = name;
        this->score = score;
    }
};

struct compare {
    bool operator()(tagStudent stu1, tagStudent stu2) {
        if (stu1.score != stu2.score) { return stu1.score < stu2.score; }
        else { return stu1.id > stu2.id; }
    }
};

int main() {
    priority_queue<tagStudent, std::vector<tagStudent>, compare> stuQueue;
    int studentCnt;
    cin >> studentCnt;
    for (int i = 0; i < studentCnt; i++) {
        string currId, currName; int currScore;
        cin >> currId >> currName >> currScore;
        tagStudent currStudent(currId, currName, currScore);
        stuQueue.push(currStudent);
    }
    while (stuQueue.size() > 0) {
        tagStudent rankedStudent = stuQueue.top();
        stuQueue.pop();
        cout << rankedStudent.id << " " << rankedStudent.name << " " << rankedStudent.score << endl;
    }
    return 0;
}